55b33f3a544832abc2100b962a5061701022c513,ontrack-job/src/test/java/net/nemerosa/ontrack/job/orchestrator/JobOrchestratorTest.java,JobOrchestratorTest,orchestrator_initial_jobs,#,40

Before Change


        // Removes the first job in the list
        jobs.remove(0);
        // ... and launches the orchestration
        scheduler.fireImmediately(key).get();
        // ... tests the jobs are registered
        assertFalse(scheduler.getJobStatus(TestJob.getKey("1")).isPresent());
        assertTrue(scheduler.getJobStatus(TestJob.getKey("2")).isPresent());

After Change


    public void orchestrator_initial_jobs() throws InterruptedException, ExecutionException {
        JobScheduler scheduler = createJobScheduler();

        Supplier<RuntimeException> notScheduledException = () -> new RuntimeException("Not scheduled");

        List<JobRegistration> jobs = new ArrayList<>();

        JobOrchestratorSupplier jobOrchestrationSupplier = jobs::stream;

        JobOrchestrator orchestrator = new JobOrchestrator(
                scheduler,
                "Test",
                Collections.singleton(jobOrchestrationSupplier)
        );
        JobKey key = orchestrator.getKey();

        // Orchestration is registered as a job, but does not run since we have a NONE schedule
        scheduler.schedule(orchestrator, Schedule.NONE);
        JobStatus status = scheduler.getJobStatus(key).orElse(null);
        assertNotNull(status);
        assertNull(status.getNextRunDate());

        // Puts a job in the list
        jobs.add(new JobRegistration(new TestJob("1"), Schedule.NONE));
        // ... and launches the orchestration
        scheduler.fireImmediately(key).orElseThrow(notScheduledException).get();
        // ... tests the job has been registered
        assertTrue(scheduler.getJobStatus(TestJob.getKey("1")).isPresent());

        // Puts the second job in the list
        jobs.add(new JobRegistration(new TestJob("2"), Schedule.NONE));
        // ... and launches the orchestration
        scheduler.fireImmediately(key).orElseThrow(notScheduledException).get();
        // ... tests the jobs are registered
        assertTrue(scheduler.getJobStatus(TestJob.getKey("1")).isPresent());
        assertTrue(scheduler.getJobStatus(TestJob.getKey("2")).isPresent());

        // Removes the first job in the list
        jobs.remove(0);
        // ... and launches the orchestration
        scheduler.fireImmediately(key).orElseThrow(notScheduledException).get();
        // ... tests the jobs are registered
        assertFalse(scheduler.getJobStatus(TestJob.getKey("1")).isPresent());
        assertTrue(scheduler.getJobStatus(TestJob.getKey("2")).isPresent());